package com.fin.quant.web.controller;

import com.fin.quant.app.asset.service.RankingService;
import com.fin.quant.app.vo.BatchRankingWrapperVO;
import com.fin.quant.app.vo.RankingTypeWrapperVO;
import com.fin.quant.app.vo.RankingWrapperVO;
import com.fin.quant.rpc.common.Result;
import com.google.common.base.Splitter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 排行榜相关API控制器
 */
@RestController
@RequestMapping("/api/v1/ranking")
@Slf4j
public class RankingController {

    @Autowired
    private RankingService rankingService;

    /**
     * 获取排行榜类型列表
     */
    @GetMapping("/types")
    public Result<RankingTypeWrapperVO> types() {
        RankingTypeWrapperVO enabledRankingTypes = rankingService.getEnabledRankingTypes();
        return Result.createSuccessResult(enabledRankingTypes);
    }

    /**
     * 获取单个排行榜数据
     */
    @GetMapping("/{typeId}")
    public Result<RankingWrapperVO> rankingByTypeId(@RequestParam(defaultValue = "10") Integer limit, @PathVariable("typeId") String typeId) {
        log.info("获取高股息率排行榜请求: limit={}", limit);

        // TODO: 实现获取高股息率排行榜逻辑
        RankingWrapperVO rankingWrapperVO = rankingService.getRankingById(typeId, limit);
        return Result.createSuccessResult(rankingWrapperVO);
    }

    /**
     * 批量获取排行榜数据
     */
    @GetMapping("/batch")
    public Result<BatchRankingWrapperVO> getBatchRankings(@RequestParam(defaultValue = "10") Integer limit,
                                                          @RequestParam(value = "types") String types) {
        log.info("获取稳定分红排行榜请求: limit={}", limit);

        List<String> typeIdList = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(types);
        BatchRankingWrapperVO batchRankings = rankingService.getBatchRankings(typeIdList, limit);

        // TODO: 实现获取稳定分红排行榜逻辑
        return Result.createSuccessResult(batchRankings);
    }
}
